package com.sitanyun.merchant.guide.frament.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.base.BaseActivity;
import com.sitanyun.merchant.guide.base.ToastUtil;
import com.sitanyun.merchant.guide.bean.ForgetBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.url.Urls;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.MediaType;

/**
 * 实名认证
 */
public class SuccesRealActivity extends BaseActivity {


    @BindView(R.id.su_img)
    ImageView suImg;
    @BindView(R.id.su_text)
    TextView suText;
    @BindView(R.id.sbm_withdrawal)
    TextView sbmWithdrawal;
    @BindView(R.id.image_right_key)
    ImageView imageRightKey;
    @BindView(R.id.message)
    TextView message;
    @BindView(R.id.tv_tjsb)
    TextView tvTjsb;
    @BindView(R.id.ll_sb)
    LinearLayout llSb;

    @Override
    public int getLayoutId() {
        return R.layout.activity_succes_real;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setFindViewById(true);
        setTitleStr("实名认证");
        if (getIntent().getStringExtra("type").equals("1")) {
            message.setText("感谢您的配合，您可以随时提现！");
            suText.setText("实名认证已通过");
            llSb.setVisibility(View.GONE);
            Glide.with(SuccesRealActivity.this).load(R.mipmap.cgsucces).into(suImg);
        } else {
            llSb.setVisibility(View.VISIBLE);
            suText.setText("实名认证未通过");
            message.setText(getIntent().getStringExtra("shibai"));
            sbmWithdrawal.setText("修改");
//            finish();
            Glide.with(SuccesRealActivity.this).load(R.mipmap.sb).into(suImg);
        }
    }

    @Override
    public void initView() {


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_tjsb, R.id.sbm_withdrawal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_tjsb:
                HashMap<String,String> hashMap= new HashMap<String,String>();
                hashMap.put("name",getIntent().getStringExtra("name"));
                hashMap.put("idNum",getIntent().getStringExtra("idNum"));
                hashMap.put("idPicFront",getIntent().getStringExtra("idPicFront"));
                hashMap.put("idPicBack",getIntent().getStringExtra("idPicBack"));
                hashMap.put("reason",getIntent().getStringExtra("shibai"));
                OkHttpUtils.postString()
                        .mediaType(MediaType.parse("application/json; charset=utf-8"))
                        .addHeader("Content-Type","application/json")
                        .addHeader("Authorization","Bearer"+ SharedPreferenceUtil.getStringData("token"))
                        .url(Urls.report)
                        .content(new Gson().toJson(hashMap))
                        .build().execute(new StringCallbacks() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        ForgetBean baseEntity=   new Gson().fromJson(response, ForgetBean.class);
                       if (baseEntity.getCode()==0){
                           ToastUtil.showToast(SuccesRealActivity.this,"已上报成功");
                       }else {
                           ToastUtil.showToast(SuccesRealActivity.this,"上报接口请求错误");
                       }
                    }
                });
                break;
            case R.id.sbm_withdrawal:
                finish();
                break;
        }
    }
}
